package cn.com.sinosoft.exam.page;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import cn.com.sinosoft.exam.annotation.PageParamer;

/**
 * 
 * Pageparam参数解析器
 * @author xl
 *
 */
public class PageParamResolver implements HandlerMethodArgumentResolver {

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return parameter.hasParameterAnnotation(PageParamer.class);
	}

	@Override
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
		PageParamer pageParamer = parameter.getParameterAnnotation(PageParamer.class);
		return PageParam.getInstance(pageParamer.page(), pageParamer.limit(), webRequest);
	}

}
